using System;
using Adaptive.Agrona;
using Adaptive.Agrona.Concurrent;
using Unity.Debug;
using Xunit;

namespace Unity.Connections.Tests
{
    public class UnityProducerTest
    {
        [Fact]
        public void MethodsTest()
        {
#pragma warning disable CS0246
            IUnityProducer testUnityProducer = new ConsoleUnityStreamProducer();
#pragma warning restore CS0246
            Assert.True(testUnityProducer.Connect(null));
            int testSendingMessageCount = 5;
            int offset = 0;
            const int messageSize = 120;
            IDirectBuffer testDirectBuffer = new UnsafeBuffer(new byte[messageSize * testSendingMessageCount]);
            for (int i = 0; i < testSendingMessageCount; i++)
            {
                testUnityProducer.AddToBatching(testDirectBuffer, offset, messageSize);
                offset = offset + messageSize;
            }
            Assert.Equal(testSendingMessageCount, testUnityProducer.CompleteBatching());

            testUnityProducer.Produce(testDirectBuffer, offset, messageSize);
            testUnityProducer.Close();
            testUnityProducer.Dispose();
        }
    }
}